package com.leaf.lowcode.service;

import com.leaf.lowcode.API.AppointmentApi;
import com.leaf.lowcode.entity.VisitorInfo;
import com.leaf.lowcode.entity.VisitorRequest;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


/**
 * 权限下放,海康威视访客免预约
 *         {
 *             "receptionistId": "bd800c37157d4c7fb08e561cb713cedc",   //是被访人的唯一id，他是海康威视国电投数据库里面的。存在问题和道一云目前是没有对应关系的。解决方案，写死。
 *                 "visitStartTime": "2018-07-26T15:00:00+08:00",
 *                 "visitEndTime": "2018-07-27T15:00:00+08:00",
 *                 "visitPurpose": "测试",
 *                 "personNum": 1,
 *                 "visitorInfo": {
 *                   "visitorName": "访客姓名A",
 *                     "gender": 1,
 *                     "phoneNo": "13325715555",   //必填字段
 *                     "plateNo": "浙A12345",
 *                     "certificateType": 111,
 *                     "certificateNo": "33900XXXXXXX333",  //必填字段 ,作用刷门禁
 *                     //"certAddr": "证件地址",
 *                     //"certIssuer": "发证机关",
 *                     "nation": 1,   //必填
 *
 *         }
 *
 *         }
 */
public class Appiont {
    public static void main(String[] args) {
      AppointmentApi  appointmentApi =new AppointmentApi();
      VisitorRequest visitorRequest = new VisitorRequest();

        Calendar calendar = new GregorianCalendar();
        calendar.add(Calendar.DAY_OF_MONTH,0);
        //一天的开始时间 yyyy:MM:dd 00:00:00
        calendar.set(Calendar.HOUR_OF_DAY,0);
        calendar.set(Calendar.MINUTE,0);
        calendar.set(Calendar.SECOND,0);
        calendar.set(Calendar.MILLISECOND,0);
        Date dayStart = calendar.getTime();
        String pattern = "YYYY-MM-dd'T'HH:mm:ssZZ";
        String startStr = DateFormatUtils.format(dayStart,pattern);
        System.out.println("startStr"+startStr);
       //一天的结束时间 yyyy:MM:dd 00:00:00
        calendar.set(Calendar.HOUR_OF_DAY,23);
        calendar.set(Calendar.MINUTE,59);
        calendar.set(Calendar.SECOND,59);
        calendar.set(Calendar.MILLISECOND,999);
        Date dayEnd = calendar.getTime();
        String endStr=DateFormatUtils.format(dayEnd,pattern);
        // 预约时间前，无法进入  9-10的预约，海康威视门禁预约成功。 8点来，无法进入
        System.out.println("startStr"+endStr);
       //写死
        visitorRequest.setReceptionistId("f6436575d656415eac49aff1b37024fd");

        visitorRequest.setVisitPurpose("test");
        visitorRequest.setPersonNum(1);
        VisitorInfo visitorInfo = new VisitorInfo();
        visitorInfo.setGender(1);
        visitorInfo.setVisitorName("tere");
        visitorInfo.setPhoneNo("10110115100");
        visitorInfo.setCertificateNo("522321199212230012");
        visitorInfo.setCertificateType(111);
        visitorInfo.setNation(1);
        visitorRequest.setVisitStartTime(startStr);
        visitorRequest.setVisitEndTime(endStr);
        visitorRequest.setVisitorInfo(visitorInfo);
        String re =appointmentApi.visitorAppointment(visitorRequest);
        System.out.println(startStr);
        System.out.println(endStr);
        System.out.println(re);
        //访客记录唯一标识，用于访客签离、已预约登记等操作


    }
}
